package jeye.dao.util;

import java.util.Properties;

import org.apache.log4j.Logger;

public class QueryFactory {
	
	private static final Logger LOG = Logger.getLogger(QueryFactory.class);
	
	public static final String INSERT_EVENT = "insertEvent";
	
	public static final String INSERT_EVENT_FRAME = "insertEventFrame";

	public static final String SELECT_EVENT_IDS = "selectEventIds";
	
	public static final String SELECT_EVENT_FRAMES_IDS_BY_EVENT_ID = "selectEventFramesIdsByEventId";
	
	public static final String SELECT_EVENT_FRAME_BY_ID = "selectEventFrameById";
	
	public static final String SELECT_EVENT_FRAMES = "selectEventFrames"; 
	
	private static final String DEFAULT_DIALECT = "default";

	private String dialect;
	
	private Properties queries;
	
	public QueryFactory(String dialect, Properties queries) {
		this.dialect = dialect;
		this.queries = queries;
	}

	public String createSQLQuery(String name) {
		String key = dialect + "." + name;
		String query = queries.getProperty(key);
		
		if(query == null) {
			key = DEFAULT_DIALECT + "." + name;
			query = queries.getProperty(key);
		}
		
		LOG.debug("Created query \"" + query +"\" for name: \"" + name + "\"");
		
		return query;
	}	
}
